package com.kh.pajx.sop.service.sys.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.dao.sys.ISysAreaDao;
import com.kh.pajx.sop.domain.SysArea;
import com.kh.pajx.sop.service.sys.ISysAreaService;

/**
 * 地区编码信息业务逻辑实现类
 * @author 
 * @return
 * @createDate 2014年6月20日 下午2:17:02
 */
@Service
@Transactional
public class SysAreaServiceImpl implements ISysAreaService {

	@Resource
	private ISysAreaDao sysAreaDao;
	
	
	@Override
	public void save(SysArea sysArea) {
		sysAreaDao.save(sysArea);
	}

	@Override
	public void delete(String areaId) {
		sysAreaDao.delete(areaId);
	}

	@Override
	public void update(SysArea sysArea) {
		sysAreaDao.update(sysArea);
	}

	@Override
	public SysArea getById(String areaId) {
		
		return sysAreaDao.getById(areaId);
	}

	@Override
	public List<SysArea> findAll() {
		return sysAreaDao.getParentArea();
	}

	@Override
	public Map<String,String> getAreaMap(){
		Map<String,String> areaMap = new HashMap<String, String>();
		List<SysArea> areaList = sysAreaDao.findAll();
		for (SysArea area:areaList) {
			areaMap.put(area.getAreaCode(), area.getAreaName());
		}
		return areaMap;
	}
	
	@Override
	public Map<String,String> getParentAreaMap(){
		Map<String,String> areaMap = new HashMap<String, String>();
		List<SysArea> areaList = sysAreaDao.getParentArea();
		for (SysArea area:areaList) {
			areaMap.put(area.getAreaCode(), area.getAreaName());
		}
		return areaMap;
	}


	@Override
	public Map<String, List<SysArea>> getAreaMap2(){
		// TODO Auto-generated method stub
		Map<String,List<SysArea>> areaMap = new HashMap<String, List<SysArea>>();//市级行政单位Map
		List<SysArea> areaList = sysAreaDao.getParentArea();//得到市级节点
		
		List<SysArea> countyList=null;
		for (SysArea area:areaList) {
			countyList=findAreaByCity(area.getAreaCode());//得到县级节点
			//Map<String,List<SysArea>> countyMap=new HashMap<String, List<SysArea>>();//区县行政单位Map
			areaMap.put(area.getAreaCode(), countyList);
		}
		return areaMap;
	}

	@Override
	public List<SysArea> findAreaByCity(String areaCode) {
		// TODO Auto-generated method stub
		return sysAreaDao.findAreaByCity(areaCode);
	}

}
